<template>
  <div>
    <h1>Add</h1>
    <div>Nickname: <input v-model="user.nickname" placeholder=""></div>
    <div>Age: <input v-model="user.age" placeholder=""></div>
    <button type="button" @click="saveUser()">创建</button>
  </div>
</template>

<script>
export default {
  data () {
    return {
      user: {
        nickname: '',
        age: 0
      }
    }
  },
  methods: {
    saveUser: function () {
      const _self = this;
      this.$ajax('user/save', 'POST', {'nickname': this.user.nickname, 'age': parseInt(this.user.age)}, function (data) {
        location.href = '/';
      });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
